extern "c"应该写在程序的什么位置?

来源:百度知道 编辑:UC知道 时间:2024/05/02 10:05:54
从 C++ 程序调用 C 函数时需要使用 extern "c".请问 extern “c”这个语句应该放在程序的什么位置?

我给你一段我以前写过的程序,你一看就知道啦
------------------------------
#include <stdio.h>

#define INT_DIGITS 20
#define ERRMSG "Error "
#define LENGTH (sizeof(ERRMSG) + 1 + INT_DIGITS)

extern int sys_nerr;
extern char *sys_errlist[];

char *strerror(n)
int n;
{
static char buf[LENGTH];
if (n >= 0 && n < sys_nerr && sys_errlist[n] != 0)
return sys_errlist[n];
else {
snprintf(buf, ERRMSG"%d", LENGTH, n);
return buf;
}
}